package com.jt.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jt.mapper.RightsMapper;
import com.jt.pojo.Rights;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RightsServiceImpl implements RightsService{

 @Autowired
 private RightsMapper rightsMapper;

 @Override
 public List<Rights> getRightsList() {
  QueryWrapper queryWrapper=new QueryWrapper();
  queryWrapper.eq("parent_Id",0);
  List<Rights> list=rightsMapper.selectList(queryWrapper);

  for(Rights rights:list){
   //queryWrapper.clear();
   QueryWrapper queryWrapper2=new QueryWrapper();
   queryWrapper2.eq("parent_Id",rights.getId());
   List<Rights> children=rightsMapper.selectList(queryWrapper2);
   rights.setChildren(children);
  }
return list;
 }

 @Override
 public Rights getRights(Rights rights) {
//        rights.setId(id);
//        QueryWrapper<Rights> queryWrapper=new QueryWrapper<>(rights);
  return rightsMapper.selectById(rights);
 }

 @Override
 public Rights getRights(Integer id) {
//        rights.setId(id);
//        QueryWrapper<Rights> queryWrapper=new QueryWrapper<>(rights);
  return rightsMapper.selectById(id);
 }


 public List<Rights> list(){
  return rightsMapper.selectList(null);
 }



}
